package com.power.service.impl;


import com.power.dao.InspeDao;
import com.power.dao.impl.InspeDaoimpl;
import com.power.ov.ResultDataTable;
import com.power.pojo.Defect;
import com.power.pojo.Inspetion;
import com.power.service.inspeService;

import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/09 10:57
 * Description:
 * Version: V1.0
 */
public class InspeServiceimpl implements inspeService {
    InspeDao inspeDao = new InspeDaoimpl();
    @Override
    public ResultDataTable QueryListInspection(int page, int limit) throws SQLException {
        System.out.println("到达后台service层"+page+"      "+limit);
        return inspeDao.QueryListInspection(page,limit);
    }

    @Override
    public int AddInspetion(Inspetion inspetion) throws SQLException {
        //创建Calendar对象
        Calendar cal=Calendar.getInstance();
        //用Calendar类提供的方法获取年、月、日、时、分、秒
        int year  =cal.get(Calendar.YEAR);   //年
        int month =cal.get(Calendar.MONTH)+1;  //月  默认是从0开始  即1月获取到的是0
        int day   =cal.get(Calendar.DAY_OF_MONTH);  //日，即一个月中的第几天
        int hour  =cal.get(Calendar.HOUR_OF_DAY);  //小时
        int minute=cal.get(Calendar.MINUTE);   //分
        int second=cal.get(Calendar.SECOND);  //秒
        Date mydate = new Date();
        //拼接成字符串输出
        String date=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
        //将当前系统时间设置为巡检信息下发时间
        inspetion.setLssue_time(date);
        //通过线路名称查询当前线路id。
        inspetion.setLine_id(queryLinaNameByLineId(inspetion));
        //通过巡检员名称查询巡检员账号
        inspetion.setInspection_accont(queryUserAcountByInspetionAcount(inspetion.getInspection_accont()));
        System.out.println("巡检员账号"+inspetion.getInspection_accont());
        return inspeDao.AddInspetion(inspetion);
    } private String queryUserAcountByInspetionAcount(String inspection_accont) throws SQLException {
        return inspeDao.queryUserAcountByInspetionAcount(inspection_accont);
    }
    private int queryLinaNameByLineId(Inspetion inspetion) throws SQLException {
        return inspeDao.queryLinaNameByLineId(inspetion);

    }

    @Override
    public ResultDataTable ShowSelectInspection() throws SQLException {
        return inspeDao.ShowSelectInspection();
    }

    @Override
    public ResultDataTable ShowSelectState() throws SQLException {
        return inspeDao.ShowSelectState();
    }

    @Override
    public ResultDataTable SearchInspection(String task_id, String line_number, int state_id) throws SQLException {
        return inspeDao.SearchInspection(task_id,line_number,state_id);
    }

    @Override
    public int EditInspetion(Inspetion inspetion) throws SQLException {
        return inspeDao.EditInspetion(inspetion);

    }

    @Override
    public int ChangeCarrieState(String task_id) throws SQLException {
        return inspeDao.ChangeCarrieState(task_id);
    }

    @Override
    public int Edit_CarriedInspe(Defect defect) throws SQLException {
        defect.setInspector_account(setUserCount(defect));
        //创建Calendar对象
        Calendar cal=Calendar.getInstance();
        //用Calendar类提供的方法获取年、月、日、时、分、秒
        int year  =cal.get(Calendar.YEAR);   //年
        int month =cal.get(Calendar.MONTH)+1;  //月  默认是从0开始  即1月获取到的是0
        int day   =cal.get(Calendar.DAY_OF_MONTH);  //日，即一个月中的第几天
        int hour  =cal.get(Calendar.HOUR_OF_DAY);  //小时
        int minute=cal.get(Calendar.MINUTE);   //分
        int second=cal.get(Calendar.SECOND);  //秒
        Date mydate = new Date();
        //拼接成字符串输出
        String date=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
        //将当前系统时间设置为巡检信息下发时间
        defect.setFind_time(date);
        return inspeDao.Edit_CarriedInspe(defect);
    }


    public String setUserCount(Defect defect) throws SQLException {
        String result = inspeDao.setUserCount(defect);
        return result;
    }
}
